package com.wulis.provider.basic.web;

import static com.wulis.common.model.enums.VersionEnum.WEB_V_1_0;

import java.util.List;

import javax.validation.Valid;

import com.wulis.common.model.enums.EnableStateEnum;
import com.wulis.provider.basic.service.PositionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wulis.common.annotation.ApiVersion;
import com.wulis.common.model.dto.IdDto;
import com.wulis.common.support.BaseController;
import com.wulis.common.wrapper.ApiWrapMapper;
import com.wulis.common.wrapper.ApiWrapper;
import com.wulis.provider.basic.model.dto.InsertPositionDto;
import com.wulis.provider.basic.model.dto.QueryPositionPageDto;
import com.wulis.provider.basic.model.dto.UpdatePositionDto;
import com.wulis.provider.basic.model.vo.QueryPositionListVo;
import com.wulis.provider.basic.model.vo.QueryPositionPageVo;
import com.wulis.provider.basic.model.vo.QueryPositionVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author WuliBao
 * @date 2020-05-21
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("web/basic/position")
@Api(tags = "基础信息管理:职位管理")
public class PositionController extends BaseController {
    private final PositionService positionService;
    
    @ApiVersion(WEB_V_1_0)
    @GetMapping("queryPositionPage")
    @ApiOperation("查询职位信息列表(分页)")
    @PreAuthorize("@api.hasPermission('web:basic:position:queryPositionPage')")
    public ApiWrapper<IPage<QueryPositionPageVo>> queryPositionPage(@Valid QueryPositionPageDto queryPositionPageDto) {
        return ApiWrapMapper.success(positionService.queryPositionPage(queryPositionPageDto));
    }
    
    @ApiVersion(WEB_V_1_0)
    @GetMapping("queryPositionList")
    @ApiOperation("查询职位信息列表(全量)")
    @PreAuthorize("@api.hasPermission('web:basic:position:queryPositionList')")
    public ApiWrapper<List<QueryPositionListVo>> queryPositionList() {
        return ApiWrapMapper.success(positionService.queryPositionList(EnableStateEnum.IS_ENABLED.value()));
    }
    
    @ApiVersion(WEB_V_1_0)
    @GetMapping("queryPosition")
    @ApiOperation("查询职位信息")
    @PreAuthorize("@api.hasPermission('web:basic:position:queryPosition')")
    public ApiWrapper<QueryPositionVo> queryPosition(@Valid IdDto idDto) {
        return ApiWrapMapper.success(positionService.queryPosition(idDto.getId()));
    }
    
    @ApiVersion(WEB_V_1_0)
    @PostMapping("insertPosition")
    @ApiOperation("新增职位信息")
    @PreAuthorize("@api.hasPermission('web:basic:position:insertPosition')")
    public ApiWrapper<Integer> insertPosition(@Valid @RequestBody InsertPositionDto insertPositionDto) {
        return ApiWrapMapper.success(positionService.insertPosition(insertPositionDto));
    }
    
    @ApiVersion(WEB_V_1_0)
    @PutMapping("updatePosition")
    @ApiOperation("修改职位信息")
    @PreAuthorize("@api.hasPermission('web:basic:position:updatePosition')")
    public ApiWrapper<Integer> updatePosition(@Valid @RequestBody UpdatePositionDto updatePositionDto) {
        return ApiWrapMapper.success(positionService.updatePosition(updatePositionDto));
    }
    
    @ApiVersion(WEB_V_1_0)
    @DeleteMapping("deletePosition")
    @ApiOperation("删除职位信息")
    @PreAuthorize("@api.hasPermission('web:basic:position:deletePosition')")
    public ApiWrapper<Integer> deletePosition(@Valid @RequestBody IdDto idDto) {
        return ApiWrapMapper.success(positionService.deletePosition(idDto.getId()));
    }
}
